//
//  KYSportTrackingLine.m
//  kyysprot
//
//  Created by HongYi on 2017/7/3.
//  Copyright © 2017年 kcvly. All rights reserved.
//

#import "KYSportTrackingLine.h"

#import "KYPolyline.h"

@implementation KYSportTrackingLine {
    CLLocation *_startLocation;
    CLLocation *_endLocation;
}

- (instancetype)initWithStartLocation:(CLLocation *)startLocation endLocation:(CLLocation *)endLocation {
    if (self = [super init]) {
        _startLocation = startLocation;
        _endLocation = endLocation;
    }
    return self;
}

- (MAPolyline *)polyline {
    CLLocationCoordinate2D polylineCoords[2];
    polylineCoords[0] = _startLocation.coordinate;
    polylineCoords[1] = _endLocation.coordinate;
    
    
//    NSLog(@"========> speed: %.1f km/h", self.speed);
//    NSLog(@"========> time: %f", self.time);
//    NSLog(@"========> distance: %f", self.distance);
    
    CGFloat factor = 16;
    CGFloat red = self.speed * factor / 255.0;
    UIColor *lineColor = [UIColor colorWithRed:red green:1.0 blue:0.0 alpha:1.0];
    KYPolyline *polyline = [KYPolyline polylineWithCoordinates:polylineCoords count:2 color:lineColor];
    return polyline;
}

- (double)speed {
    return (_startLocation.speed + _endLocation.speed) * 0.5 * 3.6;
}

- (double)time {
    return [_endLocation.timestamp timeIntervalSinceDate:_startLocation.timestamp];
}

- (double)distance {
    return [_endLocation distanceFromLocation:_startLocation] * 0.001;
}

@end
